<?php
/**
 * Created by PhpStorm.
 * User: liu85
 * Date: 2019/2/23
 * Time: 22:53
 */

namespace app\h5\controller;


use app\common\cache\SmsCache;
use app\common\consts\BaseConst;
use app\common\consts\ErrorConst;
use app\common\helper\RequestHelper;
use app\common\helper\UserHelper;
use app\common\utils\MyCrypt;
use app\common\utils\MyRedis;
use app\common\utils\SmsUtils;

class Sms extends Base
{
    public function send()
    {
        $mobile = $this->request->param('mobile');
        if(!UserHelper::checkMobile($mobile)){
            _failure('手机号格式不正确');
        }
        if(RequestHelper::checkIpOverMaxRequest()){
            _failure(ErrorConst::SEND_ERR_MSG);
        }
        if(RequestHelper::checkMobileOverMaxRequest($mobile)){
            _failure(ErrorConst::SEND_ERR_MSG);
        }
        $code = MyCrypt::makeCode(6, true);

//        $status = SmsUtils::send($mobile,$code);
//        if(!$status){
//            _failure(ErrorConst::SEND_ERR_MSG);
//        }

        $last1 = SmsCache::setMobileSmsCode($mobile, $code);
        $last2 = SmsCache::setIncIpDaySendCount(RequestHelper::getClientIp());
        $last3 = SmsCache::setIncMobileDaySendCount($mobile);
        _failure($code);
    }
}